//package com.lagou.service;
//
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.http.HttpRequest;
//import org.springframework.http.client.ClientHttpRequestExecution;
//import org.springframework.http.client.ClientHttpRequestInterceptor;
//import org.springframework.http.client.ClientHttpResponse;
//import org.springframework.stereotype.Service;
//
//import javax.servlet.http.HttpServletRequest;
//import java.io.IOException;
//
//@Service
//public class MyRestTemplateHeaderModifierInterceptor implements ClientHttpRequestInterceptor {
//
//   @Autowired
//   private HttpServletRequest req;
//
//    @Override
//    public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
//        // 这里因为项目需要根据数据库内多个域名动态生成
//        String host = request.getURI().getHost();
//        String schema = request.getURI().getScheme();
//        //request
//        // 根据 domain 生成token
//        // 根据 access_token，追加 header Bearer认证
//        Object token = req.getSession().getAttribute("token");
//
//        String accessToken = token==null?"":token.toString();
//        // 如果需要
//        // request.getHeaders().setContentType(MediaType.APPLICATION_JSON);
//        // 设置Authorization Bearer xx
//        request.getHeaders().add("token",accessToken);
//        ClientHttpResponse response = execution.execute(request, body);
//
//        return response;
//    }
//
//}
